//
//  WSAuthorheadView.m
//  GroupFourFM
//
//  Created by dllo on 15/12/30.
//  Copyright © 2015年 GroupFour. All rights reserved.
//

#import "WSAuthorheadView.h"
#import <UIImageView+WebCache.h>

@interface WSAuthorheadView ()

@property (nonatomic, strong) UIImageView *backgroundImageView;
@property (nonatomic, strong) FXBlurView *blurView;
@property (nonatomic, strong) UIImageView *avatorImageView;
@property (nonatomic, strong) UILabel *trackTitle;
@property (nonatomic, strong) UILabel *trackDigest;
@property (nonatomic, strong) UIButton *btnConcern;

@end

@implementation WSAuthorheadView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self creatSubView];
    }
    return self;
}

- (void)creatSubView {

    //背景
    self.backgroundImageView = [[UIImageView alloc] init];
    self.backgroundImageView.backgroundColor = COLOR_BG;
    self.backgroundImageView.alpha = 1;
    self.backgroundImageView.contentMode = UIViewContentModeScaleAspectFill;
    self.backgroundImageView.layer.masksToBounds = YES;
    [self addSubview:self.backgroundImageView];
    [self.backgroundImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.edges.mas_equalTo(@0);
    }];
    
    //毛玻璃
    self.blurView = [[FXBlurView alloc] init];
    [self.backgroundImageView addSubview:self.blurView];
    _blurView.blurEnabled = NO;//是否模糊
    _blurView.backgroundColor = [UIColor blackColor];//前景颜色
    _blurView.alpha = 0.3;
    [self.blurView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.edges.mas_equalTo(@0);
    }];
    
    //头像
    self.avatorImageView = [[UIImageView alloc] init];
    self.avatorImageView.backgroundColor = WHITE;
    self.avatorImageView.layer.masksToBounds = YES;
    self.avatorImageView.layer.cornerRadius = SCREEN_WIDTH*0.1;
    self.avatorImageView.layer.borderColor = WHITE.CGColor;
    self.avatorImageView.layer.borderWidth = 1;
    [self addSubview:self.avatorImageView];
    [self.avatorImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(@70);
        make.width.height.mas_equalTo(@(SCREEN_WIDTH*0.2));
        make.centerX.equalTo(self.mas_centerX);
    }];
    
    //主播名
    self.trackTitle = [[UILabel alloc] init];
    self.trackTitle.backgroundColor = CLEAR;
    self.trackTitle.textColor = WHITE;
    self.trackTitle.font = [UIFont systemFontOfSize:17 weight:0.2];
    [self addSubview:self.trackTitle];
    self.trackTitle.textAlignment = NSTextAlignmentCenter;
    [self.trackTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.avatorImageView.mas_bottom).offset(10);
        make.centerX.equalTo(self.mas_centerX);
        make.width.mas_equalTo(@(SCREEN_WIDTH*0.5));
        make.height.mas_equalTo(@(SCREEN_HEIGHT*0.03));
    }];
    
    //简介
    self.trackDigest = [[UILabel alloc] init];
    self.trackDigest.backgroundColor = CLEAR;
    self.trackDigest.font = [UIFont systemFontOfSize:13 weight:0];
    [self addSubview:self.trackDigest];
    self.trackDigest.textAlignment = NSTextAlignmentCenter;
    self.trackDigest.textColor = [UIColor whiteColor];
    [self.trackDigest mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.equalTo(self.mas_centerX);
        make.top.equalTo(self.trackTitle.mas_bottom).offset(10);
        make.width.mas_equalTo(@(SCREEN_WIDTH *0.7));
        make.height.mas_equalTo(@(SCREEN_HEIGHT*0.03));
    }];
    
    self.btnConcern = [UIButton buttonWithType:UIButtonTypeCustom];
    [self addSubview:_btnConcern];
    [self.btnConcern setBackgroundImage:[UIImage imageNamed:@"btn_unfollow_n"] forState:UIControlStateNormal];
    [self.btnConcern addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.btnConcern mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.equalTo(self.mas_centerX);
        make.top.equalTo(self.trackDigest.mas_bottom).offset(10);
        make.width.mas_equalTo(@(522 / 2 * WID));
        make.height.mas_equalTo(@(68 / 2 * HEI));
    }];
}

- (void)setModel:(WSAuthorHeader *)model {

    _model = model;
    
    [self.backgroundImageView sd_setImageWithURL:[NSURL URLWithString:_model.backgroundLogo] placeholderImage:PLACEHOLDER_IMAGE];
    if (_model.objectId != nil) {
        [self.btnConcern setBackgroundImage:[UIImage imageNamed:@"btn_follow_n"] forState:UIControlStateNormal];
    } else {
        [self.btnConcern setBackgroundImage:[UIImage imageNamed:@"btn_unfollow_n"] forState:UIControlStateNormal];
    }
    [self.avatorImageView sd_setImageWithURL:[NSURL URLWithString:_model.mobileSmallLogo] placeholderImage:PLACEHOLDER_CELL_CIRCLE];
    self.trackTitle.text = _model.nickname;
    self.trackDigest.text = _model.personalSignature;
}

- (void)btnAction:(UIButton *)button {

    [self.delegate attentionAction];
}

@end
